import React from "react";
import {inject, observer} from 'mobx-react';
import {getAntd, getComsMobx, getEcCom, getLabel} from '../../../util/convert';
import * as type from "../../../constants/type";
import {toJS} from 'mobx';

const {WeaTools} = getEcCom();
@inject('globalStore','EnableProcessInterventionStore')
@observer
export default class EnableProcessInterventionComponents extends React.Component {
    constructor(props) {
        super(props);
    }
    componentDidMount() {//一些初始化请求
        let {getDetailInfo} = this.props.EnableProcessInterventionStore;
        getDetailInfo();
    }
    componentWillReceiveProps(nextProps) {
    }
    componentWillUnmount() {
        //组件卸载时一般清理一些状态
    }
    render() {
        const { WeaDialogFooter,WeaRightMenu,WeaTableEditable } = getEcCom();
        const { initialDatas} = this.props.EnableProcessInterventionStore;
        const titledata = [
            {
                title: <span>{getLabel(522216, '序号')}</span>,
                dataIndex: 'indexnumber',
                width: '10%',
                com: [
                    {type: 'TEXT', key: 'indexnumber', hasHiddenField: true, defaultValue: '3', disabled: true}
                ],
            },{
                title: <span> </span>,
                dataIndex: 'selectid',
                width: '10%',
                com: [
                    {type: 'CheckBox', key: 'selectid'}
                ],
            },
            {
                title: <span>{getLabel(530060, '未操作者')}  </span>,
                dataIndex: 'operatorid',
                width: '20%',
                com: [
                    {type: 'BROWSER', key: 'operatorid',
                        browserConditionParam: {
                            type: "1",
                            isSingle: true,
                            viewAttr:"1",
                            dataParams:{isWfTree: 1}
                        },
                    }
                ],
            },
            {
                title: <span>{getLabel(530061, '查看状态')}</span>,
                dataIndex: 'viewtype',
                width: '20%',
                com: [
                    {type: 'TEXT', key: 'viewtype', hasHiddenField: true,  disabled: true}
                ],
            }
            ,
            {
                title: <span>{getLabel(530062, '干预原因')}</span>,
                dataIndex: 'submitoption',
                width: '40%',
                com: [
                    {type: 'INPUT', key: 'submitoption' }
                ],
            }
        ];
        return (
            <div className="wea-form-item-group" >
                <WeaRightMenu {...this.getMoreBtns()}>
                    <WeaTableEditable
                        {...this.state}
                        tableProps={this.getTableProps()}
                        columns={titledata}
                        draggable={false}//是否可拖拽
                        showTitle={false}//标题显隐
                        showAdd={false}//添加显隐
                        showDelete={false}//删除显隐
                        getRowSelection={this.getRowSelection}
                        onChange={this.onChange}
                        showCopy={false}//复制显隐
                        buttonsType={'inline'}//按钮组类型
                        pushTitleIntoHeader={false}//标题合并到title
                        showRowSelect={false}//显示行选择
                        datas={toJS(initialDatas)}
                        pageSize={10}
                        onChange={this.onChange}//数据改变
                    />
                </WeaRightMenu>
                <WeaDialogFooter buttons={this.getButtons()} moreBtn={this.getMoreBtns()} />
            </div>
        );
    }
    onChange = (datas, other, data) => {
        const {EnableProcessInterventionStore} = this.props;
        const {updateInitialDatas} = EnableProcessInterventionStore;
        updateInitialDatas(datas);
    };
    getTableProps = () => {
        return {
            scroll: {  y: 500}
        };
    };
    getRowSelection = rowSelection => {
        /* const sel = {...rowSelection};
         sel.getCheckboxProps = record => {
             return {"display":"none"};
         };
         return sel;*/
        return  null;
    }
    handleChange = value => {
        let {settextval} = this.props.EnableProcessInterventionStore;
        settextval(value);
    };
    getButtons(){
        const { Button } = getAntd();
        let buttons = [];
        buttons.push(<Button type='primary' onClick={()=>{
            this.doSubmit();
        }}>{getLabel(83446,'确定')}</Button>);
        buttons.push(<Button type='primary' onClick={()=>{
            this.doCancel();
        }}>{getLabel(201,'取消')}</Button>);
        return buttons;
    }
    doSubmit(){
        let {saveUpdateInfo} = this.props.EnableProcessInterventionStore;
        saveUpdateInfo();
    }
    doCancel(){
        const { controlDialogVisible } = this.props.globalStore;
        controlDialogVisible(type.EnableProcessIntervention,false);
    }
    getMoreBtns(){
        const { Button } = getAntd();
        let buttons = [];
        buttons.push(<Button type='primary' onClick={()=>{
            this.doSubmit();
        }}>{getLabel(83446,'确定')}</Button>);
        buttons.push(<Button type='primary' onClick={()=>{
            this.doCancel();
        }}>{getLabel(201,'取消')}</Button>);
        return buttons;
    }

}
//组件检错机制
class MyErrorHandler extends React.Component {
    render() {
        const hasErrorMsg = this.props.error && this.props.error !== "";
        return(
            <WeaErrorPage msg={ hasErrorMsg ? this.props.error : getLabel(384697, "对不起，该页面异常，请联系管理员！") } />
        );
    }
}
EnableProcessInterventionComponents = WeaTools.tryCatch( React, MyErrorHandler, { error: "" })(EnableProcessInterventionComponents);
